﻿using System;
using System.Collections.Generic;

using MosCraft.Interfaces;
using MosCraft.Utilities;

namespace MosCraft.Terrain.ChunkProviders
{
    /// <summary>
    /// An example of just a flat terrain for testing
    /// </summary>
    public class ChunkProviderFlat : IChunkGenerator
    {
        private World world;

        public ChunkProviderFlat(World world, long seed)
        {
            this.world = world;
        }

        private void generateTerrain(ref byte[] blocks)
        {
            int i = blocks.Length / 256;

            for (int x = 0; x < 16; x++)
            {
                for (int y = 0; y < 16; y++)
                {
                    for (int z = 0; z < i; z++) //Height
                    {
                        int block = 0; // air

                        if (z == 0)
                        {
                            block = Block.Bedrock.blockID;
                        }
                        else if (z <= 16)
                        {
                            block = Block.Stone.blockID;
                        }
                        else if (z <= 20)
                        {
                            block = Block.Dirt.blockID;
                        }
                        else if (z == 21)
                        {
                            block = Block.Grass.blockID;
                        }

                        blocks[x << 11 | y << 7 | z] = (byte)block;
                    }
                }
            }
        }

        public void Generate(ref Chunk chunk)
        {
            byte[] blocks = new byte[32768];
            int x = chunk.xPosition;
            int z = chunk.zPosition;

            this.generateTerrain(ref blocks);
            chunk.setData(blocks);
        }

        public void Populate(int i, int j)
        {
            
        }

    }
}
